<div id="showContent"></div>
<script type="text/html" id="detailContent">
    <div class='layui-row' style='margin-top: 20px;'>
        <div class='layui-col-sm8'>
            <div style='margin:0px 40px;line-height: 27px;'>
                <i class='layui-icon layui-icon-file-b'></i><span>{{ d.name }}</span>
                <input type="hidden" id="product_id" name="product_id" value="{{ d.id }}"/>
            </div>
        </div>
        <div class='layui-col-sm4'>
            <div class='layui-btn-group'>
                <button class='layui-btn layui-btn-normal layui-btn-sm' onclick='editInfo({{ d.id }});'>编辑</button>
                <button class='layui-btn layui-btn-normal layui-btn-sm' type='button' onclick='delInfo({{ d.id }});'>
                    删除
                </button>
            </div>
        </div>
    </div>
    <div class='layui-row' style='margin-top: 20px;'>
        <div class='layui-col-sm12'>
            <table class='layui-table'>
                <tr>
                    <td>产品编码</td>
                    <td>价格</td>
                    <td>最低销售价</td>
                    <td>成本价</td>
                </tr>
                <tr>
                    <td>{{ d.num }}</td>
                    <td>{{ d.price }}</td>
                    <td>{{ d.min_price }}</td>
                    <td>{{ d.cost_price }}</td>
                </tr>
            </table>
        </div>
    </div>
    <div class='layui-row' style='margin-top: 20px;'>
        <div class='layui-col-sm12'>
            <div class='layui-tab layui-tab-card'>
                <ul class='layui-tab-title'>
                    <li class='layui-this'>基础信息</li>
                    <li>配件信息</li>
                </ul>
                <div class='layui-tab-content'>
                    <div class='layui-tab-item layui-show'>
                        <div class='layui-card'>
                            <div class='layui-card-header'>基础信息</div>
                            <div class='layui-card-body'>
                                <table style='width: 100%;'>
                                    <tr>
                                        <td>产品名称:{{ d.name }}</td>
                                        <td>产品编码:{{ d.num }}</td>
                                    </tr>
                                    <tr>
                                        <td>价格:{{ d.price }}</td>
                                        <td>最低销售价:{{ d.min_price }}</td>
                                    </tr>
                                    <tr>
                                        <td>成本价:{{ d.cost_price }}</td>
                                        <td>产品图片:</td>
                                    </tr>

                                    <tr>
                                        <td></td>
                                        <td>
                                            <img src="{{ d.files_id }}" class="list_avatar1" alt="" width="150px"
                                                 height="150px"/>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>产品描述:{{ d.description }}</td>
                                        <td></td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                    </div>
                    <div class='layui-tab-item'>
                        <div class='layui-btn-group' style='margin:5px 0px 20px 20px;'>
                            <button class='layui-btn layui-btn-normal layui-btn-sm' type='button'
                                    onclick="showRecord('{{ d.id }}')" ;>新建配件
                            </button>
                            <button class='layui-btn layui-btn-normal layui-btn-sm'
                                    style="background-color: #fff9ec;color:#ff4411;">
                                双击编辑
                            </button>
                        </div>

                        <table class='layui-hide' id='contentTable' lay-filter='contentTable' lay-size='sm'
                               style='width: 100%'></table>
                    </div>
                </div>
            </div>

        </div>
    </div>
</script>

<script type="text/html" id="tupian2">
    <div class="userinfotitle">
        <div class="uif-avatar">
            <a href="javascript:void(0);" onclick="viewImage('{{ d.files_id }}')">
                <img src="{{ d.files_id }}" class="list_avatar1" alt="" width="50px" height="50px"/>
            </a>
        </div>
    </div>
</script>

<script>
    layui.config({
        base: szoapcpath + '/static/kaige/layuiextend/'
    }).use(['element', 'table', 'form', 'layer', 'kaige', 'glfiles'], function () {
        var element = layui.element,
            layer = layui.layer,
            table = layui.table,
            form = layui.form,
            kaige = layui.kaige,
            laytpl = layui.laytpl,
            glfiles = layui.glfiles,
            $ = layui.$;

        window.default_image = szoapcpath + "/static/img/default.png";
        //查看图片
        window.viewImage = function (imgUrl) {
            kaige.viewimage({maxwidth: 600, maxheight: 600, url: imgUrl});
        }


        window.showRecord = function (id) {
            jq.ajax({
                type: 'get',
                url: szoa.client.path + '/pages/crm/product/part.html',
                data: {},
                dataType: 'html',
                success: function (res) {
                    var index2 = layer.open({
                        id: 'part_form_box',
                        type: 1,
                        anim: 4,
                        offset: 'r',
                        area: ['750px', '450px'],
                        title: "详细页面",
                        content: res,
                        btn: ['确定', '取消'],
                        yes: function (index, layero) {
                            $("#part_form_btn_save").click()
                        },
                        success: function () {
                            var res2 = $("#partContent").html();
                            var data = {};
                            data.product_id = id;
                            laytpl(res2).render(data, function (html) {
                                $("#showPartContent").append(html);
                            });
                            var data = null;
                            glfiles.form({
                                id: 'form',
                                is_edit: true,
                                data: data
                            });
                            form.on('submit(part_form_lay_filter)', function (data) {
                                d2 = {};
                                d2.files_id = $("input[name='form_files_id']").val();
                                var _data = $("#part_form_lay").serialize();
                                var d = _data.split("&");
                                $.each(d, function (index, item) {
                                    te = [];
                                    te = item.split("=")
                                    d2[te[0]] = te[1];
                                });
                                $.ajax({
                                    type: 'POST',
                                    url: "/crm.product_part/add",
                                    data: d2,
                                    success: function (res2) {
                                        if (res2.status) {
                                            layer.msg(res2.msg, {time: 1300}, function () {
                                                table.reload("contentTable");
                                                layer.close(index2);
                                            });
                                        } else {
                                            layer.msg(res2.msg);
                                        }
                                    }
                                });
                                return false;
                            });


                        }
                    });
                },

            });
        }

        window.editRecord = function (id) {
            jq.ajax({
                type: 'get',
                url: szoa.client.path + '/pages/crm/product/part.html',
                data: {},
                dataType: 'html',
                success: function (res) {
                    var index2 = layer.open({
                        id: 'part_form_box',
                        type: 1,
                        anim: 4,
                        offset: 'r',
                        area: ['750px', '450px'],
                        title: "详细页面",
                        content: res,
                        btn: ['确定', '取消'],
                        yes: function (index, layero) {
                            $("#part_form_btn_save").click()
                        },
                        success: function () {
                            var res2 = $("#partContent").html();
                            szoa.get('/crm.product_part/edit', {id, id}, function (_data) {
                                var data = {};
                                data = _data.data;
                                laytpl(res2).render(data, function (html) {
                                    $("#showPartContent").append(html);
                                    data.list = data.fi;
                                    glfiles.form({
                                        id: 'form',
                                        is_edit: true,
                                        data: data.fi
                                    });
                                });
                            });

                            form.on('submit(part_form_lay_filter)', function (data) {
                                d2 = {};
                                d2.files_id = $("input[name='form_files_id']").val();
                                var _data = $("#part_form_lay").serialize();
                                var d = _data.split("&");
                                $.each(d, function (index, item) {
                                    te = [];
                                    te = item.split("=")
                                    d2[te[0]] = te[1];
                                });
                                $.ajax({
                                    type: 'POST',
                                    url: "/crm.product_part/edit",
                                    data: d2,
                                    success: function (res2) {
                                        if (res2.status) {
                                            layer.msg(res2.msg, {time: 1300}, function () {
                                                tableReload();
                                                layer.close(index2);
                                            });
                                        } else {
                                            layer.msg(res2.msg);
                                        }
                                    }
                                });
                                return false;
                            });


                        }
                    });
                },

            });
        }
    });

</script>